<?php

namespace System\Controller;

use System\Common\SystemController;

class IndexController extends SystemController {

    public function index()
    {
        $this->loadSystemView();
    }
    
    public function setting()
    {
        $this->system_title = '站点设置';
        $obj_serv = D('Setting', 'Service');
        $rs = $obj_serv->getSetting();
        if(!$rs)
        {
            $this->assign('is_add', 1);
        }

        if($rs['seo'])
        {
            $this->assign('seo', $rs['seo']);
        }
        
        $this->assign('act_url', U('Index/dosubmit'));
        $this->loadSystemView();
    }
    
    public function dosubmit()
    {
        $post = I('post.');
        $obj_serv = D('Setting', 'Service');
        $is_created = $post['is_add'];
        unset($post['is_add']);
        try {
            if($is_created)
            {
                $obj_serv->addData($post);
            }else
            {
                $obj_serv->updateData($post);
            }
        } catch (\Exception $e) {
            
            return $this->error($e->getMessage());
        }
        
        return $this->success('保存成功',U('Index/setting'));
    }

}